﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

/**
 * 创建时间：2014/12/9 13:25:12
 * 作者：yong.blackcore
 * Email：itblackhole@outlook.com
 * QQ：50404503
 */
namespace ComicIsland.Common.Converter
{
    public class ValueStyleConverter : IValueConverter
    {
        /// <summary>
        /// 输出格式转换 
        /// <para>评论(10)</para>
        /// <para>人气：10</para>
        /// <para>评论：10</para>
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                string format = parameter.ToString();
                string currentValue = string.Empty;
                if (value != null)
                    currentValue = value.ToString();
                //double totalValue = 0;
                //if (value != null)
                //{
                //    double.TryParse(value.ToString(), out totalValue);
                //}

                if (string.IsNullOrWhiteSpace(format))
                    return currentValue;
                else
                    return string.Format(format, currentValue);
            }
            catch (Exception err)
            {
                LogHelper.LogError(err.Message, this.GetType(), MethodBase.GetCurrentMethod());
                return "";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
}
